<?php

namespace App\Http\Requests\Admin\LandingCompany;

use App\Models\LandingCompany;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class UpdateLandingCompanyRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user('admin') !== null;
    }

    public function rules(): array
    {
        $landingCompanyId = $this->route('landingCompany')?->id ?? $this->route('landing_company');

        return [
            'name' => 'required|string|max:200',
            'short_name' => 'required|string|max:100',
            'code' => [
                'required',
                'string',
                'max:50',
                Rule::unique('landing_companies', 'code')->ignore($landingCompanyId),
            ],
            'tax_number' => 'required|string|max:50',
            'address' => 'required|string|max:500',
            'contact_person' => 'required|string|max:50',
            'phone' => 'required|string|max:20',
            'email' => 'required|email|max:100',
            'status' => 'required|in:' . implode(',', [
                LandingCompany::STATUS_ACTIVE,
                LandingCompany::STATUS_INACTIVE,
            ]),
            'billing_categories' => 'required|array|min:1',
            'billing_categories.*' => 'required|string|max:100',
            'remark' => 'required|string',
            'bank_name' => 'required|string|max:200',
            'account_number' => 'required|string|max:100',
            'balance' => 'required|numeric|min:0',
        ];
    }
}
